home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
8_13.lha
/
8_13
/
8_13b.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
51 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Check the scanset pattern for the character c.
/ Return complement for false and !complement for true.
nt checkcharset(char *pattern, int complement, int c)
char *svpat = pattern;
// special case for pattern[0] == ']'
if ((*pattern == ']') || (*pattern == '-'))
if (c == *pattern)
return !complement;
else
pattern++;
// run down the pattern
for ( ; *pattern && (*pattern != ']'); pattern++)
// either a range or trailing `-'
if (*pattern == '-')
{
// special case for trailing `-'
if (pattern[1] == ']')
{
if (c == '-')
return !complement;
}
// char range, a-z
else if ((c > pattern[-1]) &&
(c <= pattern[1]))
return !complement;
// skip past the end value of the range
else
pattern++;
}
else if (*pattern == c)
return !complement;
// The character is not in the set. pattern now
// points to the ']'. If c==-1, then return index
// of ']', else false.
if (c == -1)
return pattern - svpat;
return complement;